package com.example.day01_weather;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.day01_weather.activity.WeatherActivity;

import java.util.Observable;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.iv_lsp)
    ImageView ivLsp;
    @BindView(R.id.btn_lsp)
    Button btnLsp;
    private String[] str={"3","2","1"};
    private int a=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();

    }

    private void initView() {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        btnLsp.setText(str[a]);
                        a++;
                        if(str.length<=a){
                            Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
                            startActivity(intent);
                            timer.cancel();
                        }
                    }
                });
            }
        },1000,1000);
    }

    @OnClick(R.id.btn_lsp)
    public void onClick() {
        Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
        startActivity(intent);
    }
}
